package com.shzu.jwc.ty.service;

import java.util.List;

import com.shzu.jwc.ty.common.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.shzu.jwc.ty.bean.SystemSelectcourse;
import com.shzu.jwc.ty.bean.SystemSelectcourseExample;
import com.shzu.jwc.ty.common.ReadExcelSC;
import com.shzu.jwc.ty.common.Semester;
import com.shzu.jwc.ty.dao.SystemSelectcourseMapper;

@Service
public class SelectCourseservice {

	@Autowired
	SystemSelectcourseMapper mapper;
	
	@Autowired
	SystemYearservice systemYearservice;
	
	public List<SystemSelectcourse> search(String userStudentInfoNum){
		SystemSelectcourseExample example=new SystemSelectcourseExample();
		SystemSelectcourseExample.Criteria criteria=example.createCriteria();
		criteria.andSystemYearIdEqualTo(systemYearservice.getoneyearby(Semester.getnow()));
		criteria.andUserStudentInfoNumEqualTo(userStudentInfoNum);
		return mapper.selectByExample(example);
	}
	
	public void batchImport(String name,MultipartFile file) {
		ReadExcelSC readExcelsc=new ReadExcelSC();
		List<SystemSelectcourse> systemSelectcourses=readExcelsc.getExcelInfo(name, file);
		if(systemSelectcourses.size()!=0) {
			for(Integer i=0;i<systemSelectcourses.size();i++)
			{
				systemSelectcourses.get(i).setSystemYearId(systemYearservice.getoneyearby(Semester.getnow()));
				mapper.insert(systemSelectcourses.get(i));
			}
		}
	}
	
	public List<SystemSelectcourse> getselectcourse(Integer systemYearId){
		SystemSelectcourseExample example=new SystemSelectcourseExample();
		SystemSelectcourseExample.Criteria criteria=example.createCriteria();
		criteria.andSystemYearIdEqualTo(systemYearId);
		return mapper.selectByExample(example);
	}

	public List<SystemSelectcourse> getcourse(Integer systemYearId, Page page){
		return mapper.getselectcourse(systemYearId,page.getStartPos(),page.getPageSize());
	}

	public Integer countcourse(){
		return Math.toIntExact(mapper.countselectcourse(systemYearservice.getoneyearby(Semester.getnow())));
	}
	
}
